//思路：将第一个字符串放入到hashset，检查是否存在

import java.util.*;

public class Solution {
    public static void main(String[] args) {
        System.out.println(canConstruct("aa", "ab"));
    }

    //
    public static boolean canConstruct(String ransomNote, String magazine) {
        Map<Character, Integer> m = new HashMap<>();
        char[] ch1 = ransomNote.toCharArray();
        char[] ch2 = magazine.toCharArray();
        for (int i = 0; i < ch2.length; i++) {
            char a=ch2[i];
            if (m.containsKey(a)) {
                m.put(a, m.get(a) + 1);
            } else {
                m.put(a, 1);
            }
        }

        for (int i = 0; i < ch1.length; i++) {
            char b=ch1[i];
            if (!m.containsKey(b)) {
                return false;
            }
            if (m.get(b) == 0) {
                return false;
            }
            m.put(b, m.get(b) - 1);
        }
        return true;

    }


}













